package main

import (
	"fmt"
	"net"
	"os"
	flwLog "queue/facade/frameLog"
	"queue/library/Redis"
	"queue/log"
	"strconv"
	"time"
)

// !! 配置 go path 后自定义包任然报红时在控制台尝试执行 ： go mod init     【执行后会在项目目录下生成 /pkg/ 目录】
func flw() {
	// log ===========
	//fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
	//return
	//var logid = common.CreateLogId()
	//创建框架日志类
	flwLog.NewLogger("./runtime/", "2006-01-02", ".log")
	defer flwLog.Close()
	//创建redis日志类  "2006-01-02-15":"年-月-日-时"
	Redis.NewRedisLogger("./runtime/redis/", "2006-01-02", ".log")
	defer Redis.CloseRedisLogger()

	//test()
	//flwLog.Info(fmt.Sprintf("logId[%s] ", logid), "wefw345cvbdhtyf", []int{1, 2, 3}, 23, 42)
	//flwLog.Infof("232dvf %s g %d","fff",444)
	//fmt.Println("主进程id",os.Getpid())

	//redis=============
	//创建连接池
	Redis.NewRedisPool(Redis.DefaultCreateNum, "39.100.194.133:6379", "jwp123456", "tcp")
	defer Redis.CloseRedisPool() //关闭连接池
	//Redis.Get(logid, "name")

	Redis.BenchMain()

	//flwHttpServer.NewHttpSever("127.0.0.1", "80")
}
func flj() {
	fmt.Println("注册全局异常捕获")
	defer func() {
		if err := recover(); err != nil {
			fmt.Printf("程序异常退出，错误原因: %v\n", err)
		}
	}()

	writer, _ := log.NewWriter("./", "flj.log")
	defer writer.Close()
	for i := 1; i <= 6; i++ {
		fmt.Println("put msg to writer")
		writer.PutMsg(fmt.Sprintf("hello %d\n", i))
	}
}

func main() {
	//flj()

	flw()
}
func test() {
	//redisClient.ZAdd(redisKey, redis.Z{float64(theTime.Unix()), msgStr})
	//timeKey 时间戳做 zSet 分数，？？  redisKey := serv.conf.Topic + ":" + theTime.Format("2006010215")
	t := time.Now()
	time.Sleep(1)
	fmt.Println(time.Unix(time.Now().Unix(), 0).Format("2006010215"), "---", time.Now().Format("2006010215"))
	fmt.Println(time.Since(t).String())
	fmt.Println(time.Now().Format(time.RFC3339Nano))
	loc, _ := time.LoadLocation("Local") //重要：获取时区
	theTime, _ := time.ParseInLocation(time.RFC3339Nano, time.Now().Format(time.RFC3339Nano), loc)
	rs := theTime.Unix()
	time.Sleep(1 * time.Second)
	now := time.Now().Unix()
	fmt.Println(loc, theTime, rs-now)
	addrs, _ := net.InterfaceAddrs()
	for _, address := range addrs {
		// 检查ip地址判断是否回环地址
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				fmt.Println("iP", ipnet.IP.String())
			}
		}
	}
	fmt.Println(strconv.Itoa(os.Getpid()))
	//return
}
